package com.atguigu.yygh.shop.service.impl;

import com.atguigu.yygh.common.exception.YyghException;
import com.atguigu.yygh.common.result.ResultCodeEnum;
import com.atguigu.yygh.shop.mapper.ShopSetMapper;
import com.atguigu.yygh.model.shop.ShopSet;
import com.atguigu.yygh.shop.service.ShopSetService;
import com.atguigu.yygh.vo.order.SignInfoVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

@Service
public class ShopSetServiceImpl extends ServiceImpl<ShopSetMapper, ShopSet> implements ShopSetService {

    //2 根据传递过来商店编码，查询数据库，查询签名
    @Override
    public String getSignKey(String hoscode) {
        QueryWrapper<ShopSet> wrapper = new QueryWrapper<>();
        wrapper.eq("shopcode",hoscode);
        ShopSet hospitalSet = baseMapper.selectOne(wrapper);
        return hospitalSet.getSignKey();
    }

    @Override
    public SignInfoVo getSignInfoVo(String hoscode) {
        QueryWrapper<ShopSet> wrapper = new QueryWrapper<>();
        wrapper.eq("shopcode",hoscode);
        ShopSet hospitalSet = baseMapper.selectOne(wrapper);
        if(null == hospitalSet) {
            throw new YyghException(ResultCodeEnum.SHOP_OPEN);
        }
        SignInfoVo signInfoVo = new SignInfoVo();
        signInfoVo.setApiUrl(hospitalSet.getApiUrl());
        signInfoVo.setSignKey(hospitalSet.getSignKey());
        return signInfoVo;
    }

}
